const domainName = getApp().globalData.domainName
const parameter = getApp().globalData.parameter
const oss_domain = getApp().globalData.oss_domain

const user_id = wx.getStorageSync('user_id')

// pages/personal/personal.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    logo_green_bg:oss_domain+'static/picture/app_icon/logo_green_bg.jpeg',
    windowWidth:wx.getSystemInfoSync().windowWidth,
    menuButtonObject:wx.getMenuButtonBoundingClientRect(),
  },


  
  configuration(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/sysConfig/index/index',
    })
  },

  // 修改头像
  update_avatar(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/users/update_avatar/update_avatar?avatar=' + this.data.avatar,
    })
  },
  



  mana_certificate(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/mana_certificate/mana_certificate',
    })
  },

  certified_users(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/users/certified_users/certified_users',
    })
  },

  delete_doti_rec(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/delete_doti_rec/delete_doti_rec',
    })
  },

  // 我的招聘信息
  my_recruit(){
    getApp().get_vibration()
    let jg_list = this.data.jg_list
    if(jg_list.length>1){
      let itemList = jg_list.map(item=>item.jg_name)
      wx.showActionSheet({
        itemList: itemList,
        success: res => {
          getApp().get_vibration()
          let jg_id = jg_list[res.tapIndex].jg_id
          wx.navigateTo({
            url: '/pages/my_recruit/my_recruit?jg_id=' + jg_id
          })
        },
      })
    }else{
      let jg_id = jg_list[0].jg_id
      wx.navigateTo({
        url: '/pages/my_recruit/my_recruit?jg_id=' + jg_id
      })
    }

  },
  

  update_nick_name(e){
    wx.navigateTo({
      url: '/pages/users/update_nickName/update_nickName?nick_name=' + this.data.nick_name,
      fail:err=>{
        console.log('err',err)
      }
    })
  },


  back(){
    wx.switchTab({
      url: '/pages/index/index',
    })
  },

  // 搜索习题
  search_questions(){
    wx.navigateTo({
      url: '/pages/search_questions/search_questions',
    })
  },

  // 我的证件首页
  my_paper_index(){
    wx.navigateTo({
      url: '/pages/my_paper_index/my_paper_index',
    })
  },

  // 无人机实名认证
  uom_caac(){
    wx.navigateTo({
      url: '/pages/web_view/web_view?url=https://uom.caac.gov.cn/#/login',
    })
  },

  // 仓库管理
  warehouse(){
    let jg_list = this.data.jg_list
    let itemList = jg_list.map(x=>x.jg_name)
    wx.showActionSheet({
      itemList: itemList,
      success: res => {
        let jg_id = jg_list[res.tapIndex].jg_id
        wx.navigateTo({
          url: '/pages/warehouse/index/warehouse?jg_id=' + jg_id,
        })
      },
    })

  },

  // 申请物品
  apply_for(){
    wx.navigateTo({
      url: '/pages/warehouse/apply_for_goods/apply_for_goods',
    })
  },

  // 地图功能
  map_jg(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/map_jg/map_jg',
    })
  },

  // 机构功能按钮
  mana_jg_btns(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/mana_jg_btns/mana_jg_btns',
    })
  },

  // 文件管理
  mana_article_list(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/mana_article_list/mana_article_list',
    })
  },

  // 上传文章
  upload_article(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/upload_article/upload_article',
    })
  },

  // 习题分类
  question_classify(){
    wx.navigateTo({
      url: '/pages/question_classify/question_classify',
    })
  },


  // 习题审查
  question_check(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/sysConfig/config_textBook/question_check/question_check',
    })
  },


  // 配置课程
  mana_course(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/teaching_frame/teaching_frame',
    })
  },

  // 设置
  settings(){
      getApp().get_vibration()
    wx.navigateTo({
      url: "/pages/users/custom_settings/custom_settings",
    })
  },

  // 客户管理
  // mana_customer(){
  //     getApp().get_vibration()
  //   wx.navigateTo({
  //     url: '/pages/mana_customer/mana_customer?jg_id=' + this.data.jg_id_of_saler,
  //   })
  // },
  

  // 配置开关
  conf_switch(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/conf_switch/conf_switch',
    })
  },

  // 配置飞行训练问题
  mana_fly_problem(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/mana_fly_problem/mana_fly_problem',
    })
  },


  // 实践训练记录
  train_log_list(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/train_log_list/train_log_list?stu_id=' + user_id + '&stu_name=我',
    })
  },

  // 联系我们
  contact_us(){
    wx.showModal({
      confirmText:'我知道了',
      content: '邮箱：18683852025@163.com',
      showCancel: false,
      title: '联系我们',
    })
  },

  // 考试报名入口
  apply_exam(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/my_exam_register_list/my_exam_register_list'
    })
  },

  // 管理训练内容
  mana_train_content(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/mana_train_content/mana_train_content',
    })
  },

  //管理训练科目
  mana_train_item(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/mana_train_item/mana_train_item',
    })
  },

  // 查看模拟飞行记录
  show_sf_log(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/sf_comment_list/sf_comment_list?stu_id=' + user_id + '&stu_name=我',
    })
  },

  // 驾驶员等级管理
  mana_pilot_rank(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/mana_pilot_rank/mana_pilot_rank',
    })
  },
    
  // 轮播图管理
  mana_banner(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/mana_banner/mana_banner',
    })
  },



  // 申请加入班级
  apply_join(e){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/apply_class_rec/apply_class_rec?user_id=' + user_id 
    })
  },

  // 查看学习权限时限
  app_use_right(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/my_use_right/my_use_right?user_id=' + user_id,
    })
  },


  // 个人信息
  personal_info(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/users/basic_info/basic_info?user_id=' + user_id,
    })
  },

  // 班级管理
  mana_class(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/my_classes/my_classes',
    })
  },


  // 机构认证
  certificate_jg(){
    getApp().get_vibration()
    let jg_list = this.data.jg_list
    if(jg_list.length==1){
      let jg_id = jg_list[0].jg_id
      wx.navigateTo({
        url: '/pages/jgs/jg_homePage/jg_homePage?jg_id=' + jg_id
      })
    }else if(jg_list.length>1){
      let itemList = jg_list.map(x=>x.jg_name)
      wx.showActionSheet({
        itemList: itemList,
        success: res => {
          let tapIndex = res.tapIndex
          let jg_id = jg_list[tapIndex].jg_id
          wx.navigateTo({
            url: '/pages/jgs/jg_homePage/jg_homePage?jg_id=' + jg_id
          })
        },
      })
    }


  },

  // 机构管理
  jg_list(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/jgs/index/index'
    })
  },


  // 查看排行榜
  view_rank(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/view_rank/view_rank',
    })
  },

  // 上传视频
  mana_video(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/mana_video/mana_video',
    })
  },
  
  upload_video(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/upload_video/upload_video',
    })
  },


  // 审核学员权限
  set_stu_course(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/users/set_user/set_user'
    })
  },
  

  // 添加设备
  add_uav(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/uav_list/uav_list?acc_id=' + user_id,
    })
  },



  // 系统配置
  sys_conf(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/sys_conf/sys_conf',
    })
  },


  // 查看成绩单
  view_transcript(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/view_transcript_list/view_transcript_list?stu_id=' + user_id + '&stu_name=我' ,
    })
  },


  // 查看本人飞行记录
  show_fight_log(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/my_flight_logs/my_flight_logs?user_id=' + user_id
    })
  },

  // 发布问答咨询
  news_publish(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/news_publish/news_publish',
    })
  },

  // 意见反馈
  feedback(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/feedback_list/feedback_list',
    })
  },

  // 招聘信息管理
  mana_recruit(){
      getApp().get_vibration()
    wx.navigateTo({
      url:'/pages/mana_recruitment/mana_recruitment'
    })
  },

  // 更新用户头像昵称
  getUserProfile(){
      getApp().get_vibration()
    getApp().getUserProfile(wx.getStorageSync('open_id'))
  },

  // 我上传的习题
  my_question_bank(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/sysConfig/config_textBook/search_ti/search_ti',
    })
  },


  // 我的消息管理
  my_news(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/my_news/my_news',
    })
  },
   

  // 进入学员理论情况页面
  show_theory_statics(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/show_theory_statics/show_theory_statics',
    })
  },

  // 进入学员飞行情况页面
  show_fly_statics(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/show_fly_statics/show_fly_statics',
    })
  },

  // 进入学员地面站情况页面
  show_gs_statics(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/show_gs_statics/show_gs_statics',
    })
  },

  // 审核教员认证
  check_ins(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/check_ins/check_ins',
    })
  },

  // 审核习题
  check_ti(){
      getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/check_ti/check_ti',
    })
  },
  


  // 显示我的二维码
  show_myqrcode(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/my_qrcode/my_qrcode',
    })
  },

  // 进入地面训练记录本
  g_train_log_list(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/g_train_log_list/g_train_log_list',
    })
  },


  // 查看我的订单
  my_orders(){
    getApp().get_vibration()
    wx.showToast({
      title: '开发中，感谢关注',
      duration: 2000,
      mask: false,
    })
  },

  // 无人机管理
  mm_uav(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/mm_uav/mm_uav',
    })
  },

  // 课程列表
  course_list(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/course_list/course_list',
    })
  },

  // // 进入教员认证
  // certification_ins(){
  //   wx.navigateTo({
  //     url: '/pages/cert_ins/cert_ins?is_ins=' + getApp().globalData.is_ins + '&ins_acc_id=' + this.data.user_id,
  //   })
  // },

  // 进入我的学员管理
  // mm_students(){
  //   if(getApp().globalData.is_ins){
  //     wx.navigateTo({
  //       url: '/pages/mm_students/mm_students',
  //     })
  //   }else{
  //     wx.showModal({
  //       content: '请您先认证教员身份',
  //       showCancel: true,
  //       title: '提示',
  //       success: res => {
  //         if(res.confirm){
  //           wx.navigateTo({
  //             url: '/pages/certification_ins/certification_ins',
  //           })
  //         }
  //       },
  //     })
  //   }
  // },

  // 查询待审查课程权限的数量
  page_init(user_id){
    wx.showLoading()
    wx.request({
      url: domainName + '/personal_init',
      data: {
        user_id,
      },...parameter,
      success: res => {
        wx.hideLoading()
        this.setData({
          check_jg_count:res.data.check_jg_count,
          jg_list:res.data.jg_list,
          right_limit:res.data.right_limit,
          recruit_count:res.data.recruit_count,
          check_ti_count:res.data.check_ti_count,
          avatar:res.data.avatar,
          nick_name:res.data.nick_name,
        })
      },
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.page_init(user_id)
  },

  onPullDownRefresh(){
    this.onShow()
    wx.stopPullDownRefresh()
  },

})